<?php

namespace app\admin\model\aps;

use think\Model;

class Erpbomlog extends Model
{
    // 表名
    protected $name = 'aps_erpbomlog';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'yuqi_text',
        'zhidingjiean_text'
    ];
    

    
    public function getYuqiList()
    {
        return ['未逾期' => __('未逾期'),'逾期' => __('逾期')];
    }     

    public function getZhidingjieanList()
    {
        //0 = 已開請購單 1 = 有库存 2 = 待进料 3 = 已验收 4 = 待验收
        return ['0' => __('已開請購單'), '1' => __('有库存'), '2' => __('待进料'), '3' => __('已验收'), '4' => __('待验收')];
    }     


    public function getYuqiTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['yuqi']) ? $data['yuqi'] : '');
        $list = $this->getYuqiList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getZhidingjieanTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['zhidingjiean']) ? $data['zhidingjiean'] : '');
        $list = $this->getZhidingjieanList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function workorder()
    {
        return $this->belongsTo('Workorder', 'workorder_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function planlog()
    {
        return $this->belongsTo('Planlog', 'planlog_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
